import relayNode from "../relay";
import {GraphQLObjectType} from "graphql";
import { attributeFields, resolver } from 'graphql-sequelize';
import { Wtp, Company } from "../models";
import CompanyType from "./CompanyType";
import {fromGlobalId} from "graphql-relay";

const WtpType = new GraphQLObjectType({
  name: "Wtp",
  fields: () => Object.assign(
    {},
    attributeFields(Wtp, {
      exclude: [],
      globalId: true,
      allowNull: true,
    }),
    {
      company: {
        type: CompanyType,
        resolve: async (wtp) => {
          console.log(wtp);
          return await Company.findById(parseInt(fromGlobalId(wtp.company_id).id, 10))
        },
      }
    },
  ),
  interfaces: [relayNode.nodeInterface],
});

export default WtpType;
